/**
 * ui 面板 操作开始
 * 积分显示
 */
var AU = require("AudioUtils").inst;
var dao = require("DataDao")
cc.Class({
    extends: cc.Component,

    properties: {
        startGame: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        restartGame: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },

        continueGame: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        nextLevelGame: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        score: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        power: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        powerNode:{
            default:null,
            type:cc.Sprite
        },

        gameLogic: {
            // ATTRIBUTES:
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,    // optional, default is typeof default
            // serializable: true, // optional, default is true
        },
        rankBtn:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        setupBtn:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,    // optional, default is typeof default
            serializable: true, // optional, default is true
        },
        headLogoNode:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillNode1:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillNodeAddButton1:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,
            serializable: true,
        },
        skillNodeAddButton2:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,
            serializable: true,
        },
        skillNodeAddButton3:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,
            serializable: true,
        },
        skillNodeAddButton4:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,
            serializable: true,
        },
        skillNodeAddButton5:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Button,
            serializable: true,
        },

        skillNodeLevel1:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,
            serializable: true,
        },
        skillNodeLevel2:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,
            serializable: true,
        },
        skillNodeLevel3:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,
            serializable: true,
        },
        skillNodeLevel4:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,
            serializable: true,
        },
        skillNodeLevel5:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Label,
            serializable: true,
        },


        skillNode2:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillNode3:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillNode4:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillNode5:{
            default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        passTips:{
            default: null,
            type: cc.Node
        },
        thisLevelScoreLab:{//本关得分结算tip
            default: null,
            type: cc.Label
        },
        skillDesc:{
        	default:null,
        	type:cc.Label
        },
        skillTipsDesc:{
            default:null,
            type:cc.Label
        },
        skillTipsNode:{
            default:null,
            type:cc.Node
        },
        skillCanRaiseNode1:{
        	default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillCanRaiseNode2:{
        	default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillCanRaiseNode3:{
        	default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillCanRaiseNode4:{
        	default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillCanRaiseNode5:{
        	default: null,      // The default value will be used only when the component attaching
            type: cc.Node,
            serializable: true,
        },
        skillArrow:{
            default:null,
            type:cc.Node
        }
    },
    onSkillNodeAddButton1()
    {
        this. addSkillLevel(0);
    },
    onSkillNodeAddButton2()
    {
        this. addSkillLevel(1);
    },
    onSkillNodeAddButton3()
    {
        this. addSkillLevel(2);
    },
    onSkillNodeAddButton4()
    {
        this. addSkillLevel(3);
    },
    onSkillNodeAddButton5()
    {
        this. addSkillLevel(4);
    },
    addSkillLevel(skillId)
    {

        var global =  this.gameLogic.getComponent("GameLogic").global;
        var skillCfg = global.getSkillUp(skillId);
        var skillLevel = dao.getHeroSkill()[skillId];
        var cost = this.getGoldFun(skillLevel);
        if(dao.getGold()>=parseInt(cost)){
            this.showTips("消耗金币"+dao.getGoldLabel(cost))
            dao.addGold(-cost);
            // global.heroSkillLevel[skillId] =  global.heroSkillLevel[skillId]+1;
            dao.updateHeroSkill(skillId,skillLevel)
            this.onShow();
        }else{
            this.showTips("金币不足,请获取更多金币再来升级!")
        }
        //todo  保存数据
        // global.playDao.save( global.playDao);

    },

    getGoldFun(skillLevel)
    {
        if(skillLevel < 51)
        {
           return skillLevel *100;
        }

        if( skillLevel < 101 )
        {
            return 50*100 + (skillLevel-50)*300 ; 
        }

        
        if( skillLevel < 151 )
        {
            return 50*100 + 50*300+(skillLevel-100)*800 ; 
        }

        if(skillLevel < 201 )
        {
            return 50*100 + (50)*300 +50*800 + (skillLevel-150)*1500 ; 
        }

        return 50*(100+300+800+1500 ) + (skillLevel-200)*3000;

    },

    onStartGame()
    {
        var power = dao.powerCut();
        // 开启体力值增长
        this.powerIncreateFlag = true;
        if(power>=0){
            this.power.string=""+power;
            this.hideHeadLogNode();
            this.gameLogic.getComponent("GameLogic").startGame();
        }else{
            this.showTips("体力值不足")
        }

    },
    onRestartGame()
    {
        this.gameLogic.getComponent("GameLogic").reStartGame();
    },
    onContinueGame()
    {
        this.gameLogic.getComponent("GameLognic").continueGame();
    },
    onNextLevelGame()
    {
        // this.gameLogic.getComponent("GameLogic").nextLevelGame();
    },
    onShow()//刷新界面
    {
        if(this.gameLogic.getComponent("GameLogic").isGamePause())
        {
            this.startGame.node.active = true;
            this.powerNode.node.active = true;
            //this.continueGame.node.active = false;
            //this.restartGame.node.active = false;
            //this.nextLevelGame.node.active = false;
            this.rankBtn.node.active = true;
            this.setupBtn.node.active = true;
        }else if(this.gameLogic.getComponent("GameLogic").isGaming())
        {
            this.startGame.node.active = false;
            this.powerNode.node.active = false;
            //this.continueGame.node.active = false;
            //this.restartGame.node.active = false;
            //this.nextLevelGame.node.active = false;
            this.rankBtn.node.active = false;
            this.setupBtn.node.active = false;

        }else if(this.gameLogic.getComponent("GameLogic").isGameOver())
        {
            this.startGame.node.active = false;
            //this.continueGame.node.active = true;
            //this.restartGame.node.active = true;
            //this.nextLevelGame.node.active = false;
            this.rankBtn.node.active = true;
            this.setupBtn.node.active = true;
        }else if(this.gameLogic.getComponent("GameLogic").isPassLevel())
        {
            this.startGame.node.active = false;
            this.powerNode.node.active = false;
            //this.continueGame.node.active = true;
            //this.restartGame.node.active = true;
            //this.nextLevelGame.node.active = true;
            this.rankBtn.node.active = true;
            this.setupBtn.node.active = true;

        }
        // var global =  this.gameLogic.getComponent("GameLogic").global;
        var skill = dao.getHeroSkill();
        for(var i=0;i< skill.length;i++)
        {
            this["skillNodeLevel"+(dao.playSkill[i]+1)].string = "" + skill[i];
        }
        this.score.string = dao.getGoldLabel();

    },

    /**
     * 显示排行榜
     */
    showRankPage: function(){
        AU.playEffect(EFFECT_SELECT1,false);
        if(typeof (wx) !== "undefined"){
            wx.getOpenDataContext().postMessage({
                command: "getRank"//指令
            });
        }
        var bgRank = cc.find('Canvas/Main Camera/uiMain/RankPop');
        bgRank.active = true;
    },

    closeRankPage: function(){
        AU.playEffect(EFFECT_SELECT1,false);
        var bgRank = cc.find('Canvas/Main Camera/uiMain/RankPop');
        bgRank.active = false;
    },

    /**
     * 显示系统设置
     */
    showSetPage: function(){
        AU.playEffect(EFFECT_SELECT1,false);
        var bgSetup = cc.find('Canvas/Main Camera/uiMain/SetupPop');
        bgSetup.active = true;
    },

    closeSetPage: function(){
        AU.playEffect(EFFECT_SELECT1,false);
        var bgSetup = cc.find('Canvas/Main Camera/uiMain/SetupPop');
        bgSetup.active = false;
    },

    /*hideHeadLogNode:function(){

    	this.bieAction = cc.scaleTo(0.2, 1,0.6);

    	this.zaiAction = cc.scaleTo(0.2,0.6,1);

    	this.stretchAction = cc.scaleTo(0.2, 1.2, 1);
        this.scaleBackAction = cc.scaleTo(0.1, 1, 1);
        this.moveLeftAction = cc.moveBy(1, cc.v2(-200, 0)).easing(cc.easeCubicActionOut());
        this.moveRightAction = cc.moveBy(1, cc.v2(200, 0)).easing(cc.easeCubicActionIn());
        this.moveUpAction = cc.moveBy(1, cc.v2(0, 550)).easing(cc.easeCubicActionOut());
        this.moveDownAction = cc.moveBy(1, cc.v2(0, -200)).easing(cc.easeCubicActionIn());
        this.moveDownAction1 = cc.moveBy(0.4, cc.v2(0, -100)).easing(cc.easeCubicActionIn());
        var seq = cc.sequence(this.moveDownAction1,this.moveUpAction);
        this.headLogoNode.runAction(seq);
    },*/

    showHeadLogNode:function(){
        /*this.squashAction = cc.scaleTo(0.2, 1, 0.5);
        this.scaleBackAction = cc.scaleTo(0.2, 1, 1);
        this.moveUpAction = cc.moveBy(1, cc.v2(0, 200)).easing(cc.easeCubicActionOut());
        this.moveDownAction = cc.moveBy(1, cc.v2(0, -500)).easing(cc.easeCubicActionIn());
        var seq = cc.sequence(this.moveDownAction, this.squashAction, this.scaleBackAction);
        this.headLogoNode.runAction(seq);*/

        /**
         * 获取当前所在关卡并渲染头部
         * add by lidu at 19/6/10
         */
            // var level = dao.getCurrentLevel();
        var global =  this.gameLogic.getComponent("GameLogic").global;
        var level = global.curlevel;
        console.log("---------------level======"+level)
        var pre_level = level-1;
        var next_level = level+1;
        if(pre_level>0){
            this.headLogoNode.getChildByName("StagePre").active = true
            this.headLogoNode.getChildByName("StagePre").getChildByName("numPre").getComponent(cc.Label).string=""+pre_level;
        }else{
            this.headLogoNode.getChildByName("StagePre").active = false
        }
        this.headLogoNode.getChildByName("StagePre").getChildByName("numPre").getComponent(cc.Label).string=""+pre_level;
        this.headLogoNode.getChildByName("StageCurr").getChildByName("numCurr").getComponent(cc.Label).string=""+level;
        this.headLogoNode.getChildByName("StageSuf").getChildByName("numSuf").getComponent(cc.Label).string=""+next_level;

        this.d1 = cc.moveBy(1, cc.v2(0, -420)).easing(cc.easeCubicActionIn());
        this.u1 = cc.moveBy(0.3, cc.v2(0, 150)).easing(cc.easeCubicActionOut());
        this.d2 = cc.moveBy(0.3, cc.v2(0, -150)).easing(cc.easeCubicActionIn());
        this.u2 = cc.moveBy(0.1, cc.v2(0, 50)).easing(cc.easeCubicActionOut());
        this.d3 = cc.moveBy(0.1, cc.v2(0, -50)).easing(cc.easeCubicActionIn());
        this.u3 = cc.moveBy(0.1, cc.v2(0, 10)).easing(cc.easeCubicActionOut());
        this.d4 = cc.moveBy(0.1, cc.v2(0, -10)).easing(cc.easeCubicActionIn());
        var seq = cc.sequence(this.d1,this.u1,this.d2,this.u2,this.d3,this.u3,this.d4);
        this.headLogoNode.runAction(seq);
    },
    hideHeadLogNode:function(){
        /*this.squashAction = cc.scaleTo(0.2, 1, 0.5);
        this.scaleBackAction = cc.scaleTo(0.2, 1, 1);
        this.moveUpAction = cc.moveBy(1, cc.v2(0, 200)).easing(cc.easeCubicActionOut());
        this.moveDownAction = cc.moveBy(1, cc.v2(0, -500)).easing(cc.easeCubicActionIn());
        var seq = cc.sequence(this.moveDownAction, this.squashAction, this.scaleBackAction);
        this.headLogoNode.runAction(seq);*/

        this.bieAction = cc.scaleTo(0.2, 1, 0.5);
        this.backAction = cc.scaleTo(0.2, 1, 1);
        this.upAction = cc.moveBy(0.3, cc.v2(0, 420)).easing(cc.easeCubicActionIn());
        var seq = cc.sequence(this.bieAction,this.backAction,this.upAction);
        this.headLogoNode.runAction(seq);
    },
    hideRankBtn:function(){

    },
    showRankBtn:function(){
        this.rightAction = cc.moveBy(0.3, cc.v2(250, 0)).easing(cc.easeCubicActionIn());
        this.bieAction = cc.scaleTo(0.3, 0.5,1);
        this.kuanAction = cc.scaleTo(0.2, 1.2,1);
        this.leftAction = cc.moveBy(0.15, cc.v2(-150, 0)).easing(cc.easeCubicActionIn());
        this.backAction = cc.scaleTo(0.1, 1, 1);
        var seq = cc.sequence(this.rightAction,this.bieAction,this.kuanAction,this.leftAction,this.backAction);
        this.rankBtn.node.runAction(seq);
    },
    hideSetupBtn:function(){},
    showSetupBtn:function(){
        this.rightAction = cc.moveBy(0.3, cc.v2(300, 0)).easing(cc.easeCubicActionIn());
        this.bieAction = cc.scaleTo(0.3, 0.5,1);
        this.kuanAction = cc.scaleTo(0.2, 1.2,1);
        this.leftAction = cc.moveBy(0.15, cc.v2(-200, 0)).easing(cc.easeCubicActionIn());
        this.backAction = cc.scaleTo(0.1, 1, 1);
        var seq = cc.sequence(this.rightAction,this.bieAction,this.kuanAction,this.leftAction,this.backAction);
        this.setupBtn.node.runAction(seq);
    },
    showStartGame:function(){
        this.leftAction = cc.moveBy(0.5, cc.v2(-450, 0)).easing(cc.easeCubicActionIn());
        this.bieAction = cc.scaleTo(0.2, 0.3,1);
        this.backAction = cc.scaleTo(0.1, 1,1);
        var seq = cc.sequence(this.leftAction,this.bieAction,this.backAction);
        this.startGame.node.runAction(seq);
    },
    showPowerIncreate:function(){
        this.leftAction = cc.moveBy(0.5, cc.v2(-350, 0)).easing(cc.easeCubicActionIn());
        this.bieAction = cc.scaleTo(0.2, 0.3,1);
        this.backAction = cc.scaleTo(0.1, 1,1);
        var seq = cc.sequence(this.leftAction,this.bieAction,this.backAction);
        this.powerNode.node.runAction(seq);
    },
    showSkillIcon:function(skillNodes){
        this.upAction = cc.moveBy(0.3, cc.v2(0, 220)).easing(cc.easeCubicActionIn());
        this.bieAction = cc.scaleTo(0.3, 1,0.5);
        this.kuanAction = cc.scaleTo(0.2, 1,1.2);
        this.downAction = cc.moveBy(0.15, cc.v2(0, -100)).easing(cc.easeCubicActionIn());
        this.backAction = cc.scaleTo(0.1, 1, 1);
        var seq = cc.sequence(this.upAction,this.bieAction,this.kuanAction,this.downAction,this.backAction);
        if(skillNodes.length != 0){
            this.scheduleOnce(function(){
                skillNodes[0].runAction(seq);
                skillNodes.splice(0,1);
                if(skillNodes.length != 0){
                    this.showSkillIcon(skillNodes);
                }else{
                    return;
                }
            },0.1);
        }else{
            return;
        }
    },
    popTipOut:function(){
        this.moveRightAction = cc.moveBy(0.3, cc.v2(600, 0)).easing(cc.easeCubicActionIn());
        this.passTips.runAction(this.moveRightAction);
    },
    popTipIn:function(){
        this.moveLeftAction = cc.moveBy(0.3, cc.v2(-600, 0)).easing(cc.easeCubicActionIn());
        this.passTips.runAction(this.moveLeftAction);
    },
    /**
     * 弹出提示框showTipWithInofStr
     */
    showTipWithInofStr:function(str){
        var thisLevelScoreLab = cc.find('Canvas/Main Camera/uiMain/PassTIps/thisLevelScoreLab').getComponent(cc.Label);
        thisLevelScoreLab.string = str;
        this.moveRightAction = cc.moveBy(0.3, cc.v2(600, 0)).easing(cc.easeCubicActionIn());
        this.passTips.runAction(this.moveRightAction);
        this.scheduleOnce(function(){
            this.moveLeftAction = cc.moveBy(0.3, cc.v2(-600, 0)).easing(cc.easeCubicActionIn());
            this.passTips.runAction(this.moveLeftAction);
        },0.5);
    },
    /**
     * 关卡结束弹出 到下一关
     */
    gameOverPopTipToNext:function(gold){
        this.setTipString("历害了，恭喜过关。")//\t过关奖励："+dao.getGoldLabel(gold));
        this.popTipOut();
        this.scheduleOnce(function(){
            this.popTipIn();
            this.gameLogic.getComponent("GameLogic").nextLevelGame();
        },3);
    },
    /**
     * 关卡结束弹出 继续本关
     */
    gameOverPopTipToCurr:function(gold){
        this.setTipString("手速不行，继续努力。")//\t辛苦费："+dao.getGoldLabel(gold));
        this.popTipOut();
        this.scheduleOnce(function(){
            this.popTipIn();
            this.gameLogic.getComponent("GameLogic").reStartGame();
        },3);
    },
    setTipString:function(data){
        this.thisLevelScoreLab.string = ""+data
    },
    /**
     * 显示提示框
     * @param tip 显示的内容
     * @param closeTime 自动关注的时间 默认2秒
     */
    showTips(tip,closeTime){
        this.setTipString(tip);
        this.popTipOut();
        this.scheduleOnce(function(){
            this.popTipIn()
        },closeTime||2)
    },
    /**
     * 呈现技能介绍
     * @param index
     */
    showSkillIntroduce(index){
        if(index<=0){
            return;
        }
        var posi = this.skillArrow.getPosition();
        posi.x = posi.x + (index-1)*97.5;
        this.skillArrow.setPosition(posi);
        var str = dao.tips[index-1]+"\n"
        if(index==1){
            str += "平行空间：遁入平行空间，一段时间内不会受到少航";
        }else if(index==2){
            str += "二向箔：将关卡内的弹幕体积变小";
        }else if(index==3){
            str += "自动驾驶：被撞击的一瞬间，有一定几率闪避";
        }else if(index==4){
            str += "粒子护盾：充能后可以抵挡一次撞击";
        }else if(index==5){
            str += "空间折叠：减小地球的碰撞体积";
        }

        var skillId = index-1;
        var global =  this.gameLogic.getComponent("GameLogic").global;
        var skillCfg = global.getSkillUp(skillId);
        var skillLevel = dao.getHeroSkill()[skillId];

        var cdTime =parseInt(skillCfg.cdTime(skillCfg,skillLevel)*10)/10;
        var time = parseInt(skillCfg.bufferEffect(skillCfg,skillLevel)*1000)/1000;

        var st = "";
        if(skillId == 0)
        {
            st = st +"\n技能cd：" + cdTime;
            st = st +"\t\t\t隐身时长：" + time;
        }else if(skillId == 1)
        {
            st = st +"\n技能cd：" + "无";
            st = st +"\t\t\t：无视敌方大小：" + time;
        }else if(skillId == 2)
        {
            st = st +"\n技能cd：" + "无";
            st = st +"\t\t\t：碰撞闪避率：" + time;
        }else if(skillId == 3)
        {
            st = st +"\n技能cd：" + cdTime;
            st = st +"\t\t\t：抵挡一次伤害：" ;
        }else if(skillId == 4)
        {
            st = st +"\n技能cd：" + "无";
            st = st +"\t\t\t：折叠自我大小：" + time;
        }



        this.skillTipsDesc.string=str+st
        var moveLeftAction = cc.moveBy(0.3, cc.v2(-670, 0)).easing(cc.easeCubicActionIn());
        this.skillTipsNode.runAction(moveLeftAction);
    },
    /**
     * 隐藏技能介绍
     */
    hideSkillIntroduce(){
        var moveBackAction = cc.moveTo(0.3, cc.v2(675, -274)).easing(cc.easeCubicActionIn());
        this.skillTipsNode.runAction(moveBackAction);
    },
    callShowSkillIcon:function(){
        var skillNodes = new Array()
        skillNodes[0]=this.skillNode1;
        skillNodes[1]=this.skillNode2;
        skillNodes[2]=this.skillNode3;
        skillNodes[3]=this.skillNode4;
        skillNodes[4]=this.skillNode5;
        this.showSkillIcon(skillNodes);
    },
    /**
     * 初始化分数和体力值
     * add by lidu at 19/6/10
     */
    initScoreAndPower:function(){
        // var gold = dao.getGold();
        // var power = dao.getCurrentPower();
        this.score.string = dao.getGoldLabel();
        // this.power.string = ""+power;
    },
    
    /**
     * 是否播放技能提示动画
     */
    isSkillCanRaise : function(){
    	var scrn = new Array();
    	scrn[0]=this.skillCanRaiseNode1;
        scrn[1]=this.skillCanRaiseNode2;
        scrn[2]=this.skillCanRaiseNode3;
        scrn[3]=this.skillCanRaiseNode4;
        scrn[4]=this.skillCanRaiseNode5;
    	for(var i=0;i<5;i++){
    		var global =  this.gameLogic.getComponent("GameLogic").global;
	        var skillCfg = global.getSkillUp(i);
	        var skillLevel = dao.getHeroSkill()[i];
	        var cost = this.getGoldFun(skillLevel);
	        if(dao.getGold()>=parseInt(cost)){
			    scrn[i].active = true;
	        }else{
	        	scrn[i].active = false;
	        }
    	}
    },
    /**
     * 获取技能详情
     * @param {Object} skillId
     */
    getSkillInfo : function(skillId){
    	var global =  this.gameLogic.getComponent("GameLogic").global;
        var skillCfg = global.getSkillUp(skillId);
        var skillLevel = dao.getHeroSkill()[skillId];
        var cost = this.getGoldFun(skillLevel);
        var cdTime =parseInt(skillCfg.cdTime(skillCfg,skillLevel)*10)/10;
        var time = parseInt(skillCfg.bufferEffect(skillCfg,skillLevel)*1000)/1000;

        var st = "技能"+skillId+skillCfg.detail+ "\n"+
        "等级lv."+skillLevel+"\t\t\t升级消耗:"+cost;

        if(skillId == 0)
        {
            st = st +"\n技能cd：" + cdTime;
            st = st +"\t\t\t隐身时长：" + time;
        }else if(skillId == 1)
        {
            st = st +"\n技能cd：" + "无";
            st = st +"\t\t\t：无视敌方大小：" + time;
        }else if(skillId == 2)
        {
            st = st +"\n技能cd：" + "无";
            st = st +"\t\t\t：碰撞闪避率：" + time;
        }else if(skillId == 3)
        {
            st = st +"\n技能cd：" + cdTime;
            st = st +"\t\t\t：抵挡一次伤害：" ;
        }else if(skillId == 4)
        {
            st = st +"\n技能cd：" + "无";
            st = st +"\t\t\t：折叠自我大小：" + time;
        }

        this.skillDesc.string = st;
        
     
    },

    onLoad(){
        this.showHeadLogNode();
        // this.initScoreAndPower();
        this.showRankBtn();
        this.showStartGame();
        this.showPowerIncreate()
        this.scheduleOnce(function(){
            this.showSetupBtn();   //需要延时操作的内容
        },0.2);
        this.callShowSkillIcon();
        this.startPowerIncreate(this.powerNode);
		this.isSkillCanRaise();
		this.showSkillIntroduce(dao.getSkillIntroduceIndex())
        if(typeof (wx) !== "undefined") { //小游戏移动设备环境下
            wx.showShareMenu({
                withShareTicket: true
            });//开启转发按钮
            //监听右上角的分享调用
            wx.onShareAppMessage(function(res){
                return {
                    title: "快来玩,充钱不卡...",
                    imageUrl: REMOTE_IMG_1,
                    success(res){
                        console.log("转发成功!!!")
                    },
                    fail(res){
                        console.log("转发失败!!!")
                    }
                }
            });
        }
        /**
         * 保存数据到服务器
         */
        dao.gameLogin()
    },
    /**
     * 开始回升体力值
     * @param sprite
     */
    startPowerIncreate(sprite){
        var offLineIncreate = dao.getPowerIncreateOffLine();
        if(offLineIncreate>0){
            this.showTips("离线的时候新增体力值："+offLineIncreate,3)
        }
        this.powerCount = dao.powerCount?dao.powerCount:0;

        var fr = 1.0*this.powerCount/dao.powerIncreateFrequency;
        sprite.fillRange = fr;

        var power = dao.getCurrentPower();
        this.power.string=""+power;
        if(power>=dao.maxPower){
            this.powerIncreateFlag = false;
        }else{
            this.powerIncreateFlag = true;
        }
        this.schedule(function(){
            if(this.powerIncreateFlag==false){
                return;
            }
            this.powerCount++;
            var fillRange = 1.0*this.powerCount/dao.powerIncreateFrequency;
            sprite.fillRange = fillRange;
            if(this.powerCount>=dao.powerIncreateFrequency){
                this.powerCount = 0;
                var power = dao.powerIncrease();
                this.power.string=""+power;
                if(power>=dao.maxPower){
                    this.powerIncreateFlag = false;
                }
            }
        },1)
    },

    update(dt)
    {
        if(this.gameLogic.getComponent("GameLogic").isGaming()){
            this.score.string = Math.floor( this.gameLogic.getComponent("GameLogic"). GetScore());
        }
        // this._updateFillRange(this.powerNode, 1, dt);
    },


    _updateFillRange: function (sprite, range, dt) {
        var fillRange = sprite.fillRange;
        fillRange = fillRange < range ? fillRange += (dt * 0.1) : 0;
        sprite.fillRange = fillRange;
    },
    onDestroy(){
        /**
         * 保存当前计时器的值，防止重装加载场景的时候刷新掉
         */
        dao.powerCount = this.powerCount
    }

});